import { h, render } from 'vue'
import XtxConfirm from './index.vue'
// 1. 准备盛放的容器
const ConfirmContainer = document.createElement('div')
ConfirmContainer.className = 'Xtx-Confirm'
document.body.appendChild(ConfirmContainer)
type parmasType = {
  title: string
  text: string
}
// 导出函数
// 函数中使用h+render函数创建并挂载虚拟DOm
export default function Confirm({ title, text }: parmasType) {
  return new Promise((resolve, reject) => {
    const cancel = () => {
      // console.log('取消')
      render(null, ConfirmContainer)
      reject('cancel')
    }
    const confirm = () => {
      // console.log('确认')
      render(null, ConfirmContainer)
      resolve('confirm')
    }
    const Vnode = h(XtxConfirm, { title, text, cancel, confirm })
    render(Vnode, ConfirmContainer)
  })
}
